#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 110;
int f[N][N];
int n, k;
int main()
{
	cin >> n >> k;
	int x;
	memset(f, -0x3f, sizeof(f));
	f[0][0] = 0;	
	for (int i = 1; i <= n; i++) {
		cin >> x;
		for (int j = 0; j < k; j++) {
			f[i][j] = max(f[i - 1][j], f[i - 1][(j + k - x % k) % k] + x);
		}
	}
	cout << f[n][0] << endl;
	return 0;
}